package SSF.OS.TCP;
/**
 * MasterInstr.java
 *
 *
 * Created: Thu Aug 19 14:34:03 1999
 *
 * @version 0.7.0
 */
import java.io.*;

/** Second instrumentation class recording the number of active connections
 * and timeout events.
 */
public class MasterInstr  {

  /********************* Attribute Variables *********************/
  /**
   * reference of the monitored TCP session.
   */
  tcpSessionMaster tcpsess;

  /** print writer for output*/
  PrintWriter wrto = null;
  PrintWriter wconns = null;

  /** event type*/
  static final public int EVT_TIMEOUT = 0;
  static final public int EVT_COUNTCONNS = 1;

  /** timeout counter*/
  int timeouts;

  /************************* Constructors ************************/

  public MasterInstr(tcpSessionMaster tcp, PrintWriter conns, PrintWriter rto)
  {
    tcpsess = tcp;
    wrto = rto;
    wconns = conns;
  }
  

  /************************ Class Methods ***********************/

  /** record the number of active connections and timeout event*/
  public void takeSnapshot(float time, int evtType){
    if(wconns == null)
      return;
    switch(evtType){
    case EVT_COUNTCONNS:
      wconns.println(time + " " + tcpsess.conCounter + " " + 
                     tcpsess.actCounter + " " + timeouts);
      timeouts = 0;
      break;
    default:
      break;
    }
    wconns.flush();
  }
  
  void timeoutRecord(float stime, float etime, int flowID, double rtoVal){
    timeouts++;
    wrto.println(stime + " " + etime + " " + flowID + " " + rtoVal);
    wrto.flush();
  }
    

} // MasterInstr
